// Decompiled by DJ v3.11.11.95 Copyright 2009 Atanas Neshkov  Date: 1/30/2010 10:58:33 PM
// Home Page: http://members.fortunecity.com/neshkov/dj.html  http://www.neshkov.com/dj.html - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   MazeImpl.java


public class MazeImpl
    implements Maze, Cloneable
{

    public MazeImpl(int i, int j)
    {
        width = i;
        height = j;
        northWallExists = new boolean[i][j + 1];
        for(int k = 0; k < i; k++)
        {
            for(int l = 0; l < j + 1; l++)
                northWallExists[k][l] = true;

        }

        westWallExists = new boolean[i + 1][j];
        for(int i1 = 0; i1 < i + 1; i1++)
        {
            for(int j1 = 0; j1 < j; j1++)
                westWallExists[i1][j1] = true;

        }

    }

    protected MazeImpl(MazeImpl mazeimpl)
    {
        width = mazeimpl.width;
        height = mazeimpl.height;
        northWallExists = (boolean[][])mazeimpl.northWallExists.clone();
        westWallExists = (boolean[][])mazeimpl.westWallExists.clone();
    }

    public Object clone()
    {
        return new MazeImpl(this);
    }

    public int getWidth()
    {
        return width;
    }

    public int getHeight()
    {
        return height;
    }

    public int getStartXPosition()
    {
        return 0;
    }

    public int getStartYPosition()
    {
        return 0;
    }

    public int getEndXPosition()
    {
        return width - 1;
    }

    public int getEndYPosition()
    {
        return height - 1;
    }

    public boolean canMoveNorthFrom(int i, int j)
    {
        checkPosition(i, j);
        return !northWallExists[i][j];
    }

    public boolean canMoveSouthFrom(int i, int j)
    {
        checkPosition(i, j);
        return !northWallExists[i][j + 1];
    }

    public boolean canMoveEastFrom(int i, int j)
    {
        checkPosition(i, j);
        return !westWallExists[i + 1][j];
    }

    public boolean canMoveWestFrom(int i, int j)
    {
        checkPosition(i, j);
        return !westWallExists[i][j];
    }

    public void addWallNorthOf(int i, int j)
    {
        checkPosition(i, j);
        northWallExists[i][j] = true;
    }

    public void addWallSouthOf(int i, int j)
    {
        checkPosition(i, j);
        northWallExists[i][j + 1] = true;
    }

    public void addWallEastOf(int i, int j)
    {
        checkPosition(i, j);
        westWallExists[i + 1][j] = true;
    }

    public void addWallWestOf(int i, int j)
    {
        checkPosition(i, j);
        westWallExists[i][j] = true;
    }

    public void removeWallNorthOf(int i, int j)
    {
        checkPosition(i, j);
        northWallExists[i][j] = false;
    }

    public void removeWallSouthOf(int i, int j)
    {
        checkPosition(i, j);
        northWallExists[i][j + 1] = false;
    }

    public void removeWallEastOf(int i, int j)
    {
        checkPosition(i, j);
        westWallExists[i + 1][j] = false;
    }

    public void removeWallWestOf(int i, int j)
    {
        checkPosition(i, j);
        westWallExists[i][j] = false;
    }

    private void checkPosition(int i, int j)
    {
        if(i < 0 || i >= width || j < 0 || j >= height)
            throw new IllegalArgumentException("invalid position (" + i + ", " + j + ")");
        else
            return;
    }

    private int width;
    private int height;
    private boolean northWallExists[][];
    private boolean westWallExists[][];
}
